﻿using System;
using System.Collections.Generic;

using AutoduelClient.GameClient.Network;
/* Autoduel Game
 * CS4911 Senior Design Project
 * Fall 2010 Semester
 * Ian Axelrod, Liz Ha, Andrew Muldowney, Edward Futch
 */
using Microsoft.Xna.Framework;
using AutoduelClient.GameClient.Player;

namespace AutoduelClient.GameClient.Locations
{
    /// <summary>
    /// Represents the abstract location class with
    /// attributes common to all locations
    /// </summary> 
    public abstract class Location
    {
		#region Static Methods (1)
		/// <summary>
        /// Decode the packet and return the proper location object
        /// </summary>
        /// <param name="packet">The packet to decode</param>
        /// <returns>The resulting location</returns>
        public static Location DecodePacket(byte[] packet)
        {
            switch (packet[0])
            {
                case (byte)OPCODES.ORD_UPDLOC:
                    {
                        int i = 1;

                        string className = Util.MakeString(packet, ref i);

                        switch (className)
                        {
                            case "TruckStop":
                                {
                                    TruckStop truckStop = new TruckStop();

                                    truckStop.Name = Util.MakeString(packet, ref i);
                                    List<string> rumors = new List<string>();
                                    int i4 = i + 4;

                                    for (int j = Util.ReverseInt32(BitConverter.ToInt32(packet, i)); j > 0; j--) {
                                        rumors.Add(Util.MakeString(packet, ref i4));
                                    }
                                    truckStop.Rumors = rumors.ToArray();
                                    truckStop.Entrance = new Coordinate(Util.ReverseInt32(BitConverter.ToInt32(packet, i4)),
                                        Util.ReverseInt32(BitConverter.ToInt32(packet, i4 + 4)));

                                    System.Diagnostics.Debug.WriteLine("LOADED LOCATION: " + truckStop.ToString());
                                    return truckStop;
                                }
                            case "Arena":
                                {
                                    return null;
                                }
                            default:
                                {
                                    return null;
                                }
                        }
                    }
                default:
                    return null;
            }
        }
		#endregion

		#region Fields (4)
		// location entrance
        private Coordinate entrance;

		// hour & minute the location closes
        private int hourClose;
		// NOTE: hourOpen and hourClose requires 4 digits (military time)
        // hour & minute the location opens for business
        private int hourOpen;

		// location name
        private string name;
		#endregion

		#region Properties (4)
		/// <summary>
        /// Gets/Sets the location entrance
        /// </summary>
        public Coordinate Entrance
        {
            get { return entrance; }
            set { entrance = value; }
        }
		/// <summary>
        /// Gets/Sets the hour & minute the location closes
        /// </summary>
        public int HourClose
        {
            get { return hourClose; }
            set { hourClose = value; }
        }
		/// <summary>
        /// Gets/Sets the hour & minute the location opens
        /// </summary>
        public int HourOpen
        {
            get { return hourOpen; }
            set { hourOpen = value; }
        }
		/// <summary>
        /// Gets/Sets the location name
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
		#endregion

		#region Methods (2)

		/// <summary>
        /// Provide the menu options for this location
        /// </summary>
        /// <returns>The menu options for this location</returns>
        public abstract MenuChoice[] ProvideMenuChoices();

        /// <summary>
        /// Enter the location
        /// </summary>
        /// <param name="player">The player entering the location</param>
        public abstract void Enter(Player.Player player);

        /// <summary>
        /// Exit the location
        /// </summary>
        public abstract void Exit();

		#endregion
    }
}
